package com.iee.patterns.example.strategy.shareEnum;

import java.util.HashMap;
import java.util.Map;

// 分享工厂
public class ShareFactory {
    // 定义策略枚举
    enum ShareType {
        SINGLE("single", "单商品"),
        MULTI("multi", "多商品"),
        ORDER("order", "下单");
        // 场景对应的编码
        private String code;

        // 业务场景描述
        private String desc;

        ShareType(String code, String desc) {
            this.code = code;
            this.desc = desc;
        }

        public String getCode() {
            return code;
        }

        public Map<String, String> test(){
            return null;
        }
        // 省略 get set 方法
    }

    // 定义策略map缓存
    private static final Map<String, ShareStrategy> shareStrategies = new HashMap<>();

    static {
        shareStrategies.put("order", new OrderItemShare());
//        shareStrategies.put("single", new SingleItemShare());
//        shareStrategies.put("multi", new MultiItemShare());
    }

    // 获取指定策略
    public static ShareStrategy getShareStrategy(String type) {
        if (type == null || type.isEmpty()) {
            throw new IllegalArgumentException("type should not be empty.");
        }
        return shareStrategies.get(type);
    }

}
